import json

class SocialCLI:
    def __init__(self):
        from pathlib import Path
        from .network import SocialNetwork
        with open(Path(__file__).parent.parent.parent / 'ressources' / 'students.json') as f:
            data = json.load(f)
        self.network = SocialNetwork(data['students'])

    def run(self):
        while True:
            print("\nUniversity Social Network System")
            print("--------------------------------")
            print("0. Return to Main Menu")
            print("1. Get Friends")
            print("2. Add Friend")
            print("3. Filter by Interest")
            print("4. Define Communities")
            print("5. Find Bridges")
            print("6. Show All Users")

            choice = input("Enter your choice: ")

            if choice == '1':
                username = input("Enter username: ")
                print(self.network.get_friends(username))
            elif choice == '2':
                user = input("Your username: ")
                friend = input("Friend's username: ")
                print(self.network.add_friend(user, friend))
            elif choice == '3':
                interest = input("Enter interest: ")
                print(self.network.filter_by_interest(interest))
            elif choice == '4':
                communities = self.network.define_communities()
                for comm in communities:
                    print(f"{comm[0]}: {comm[1]}")
            elif choice == '5':
                bridges = self.network.find_bridges()
                for bridge in bridges:
                    print(f"{bridge['communities'][0]} <-> {bridge['communities'][1]}: {bridge['bridges']}")
            elif choice == '6':
                users = self.network.get_all_users()
                for user in users:
                    print(f"Username: {user['username']} | Interests: {', '.join(user['interests'])}")
            elif choice == '0':
                insure = input("Are you sure you want to return to the main menu? (y/n): ")
                if insure.lower() == 'y':
                    break
            else:
                print("Invalid choice")